﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using NetCoreCMS.IServices;
using NetCoreCMS.Models;
using NetCoreCMS.ShopCart;

namespace NetCoreCMS.Web.Areas.Web.Controllers
{
    public class CartController : BaseController
    {
        public List<cart_items> goodsList = new List<cart_items>();
        public cart_total goodsTotal = new cart_total();
        public IArticleService _article { get; set; }
        public IArticle_goodsService _article_goods { get; set; }
        public IUser_groupsService _user_groups { get; set; }
        public IActionResult Index()
        {
            int group_id = 0; //会员组ID
            Users userModel = GetUserInfo(); //会员信息
            if (userModel != null)
            {
                group_id = userModel.group_id; //如果是已登录则将会员组ID赋值
            }
            ShopCartHelper shopcart = new ShopCartHelper(_article, _user_groups, _article_goods,HttpContext);
            goodsList = shopcart.GetList(group_id); //商品列表
            if (goodsList != null)
            {
                goodsTotal = shopcart.GetTotal(goodsList); //商品统计
            }
            else
            {
                goodsList = new List<cart_items>();
                goodsTotal = new cart_total();
            }
            ViewBag.goodsList = goodsList;
            ViewBag.goodsTotal = goodsTotal;
            return View();
        }
    }
}